<?php
	/**
	 *	Copyright (c) TeamFlamingo And gray 2004-2009
	 *	www.me-live.com.cn / www.i-gray.cn
	 *
	 *	[ WARNING ]
	 *		This is NOT a freeware!
	 *		You MUST get author's authorization before using it!
	 *	[ WARNING ]
	 *
	 *	Name : view.php / Development Code Evolve
	 *	Created / Modify : 2010-2-17 / --
	 */

	if( !defined( 'IN_TEAME' ) )
	{
		exit( 'Access Denied' );
	}

	include	ME_CORE . '/paging.h.php';

	$tid	=	getMeInt( $MDK['t'] );

	$postsInfo	=	$db->assoc( $db->query( "SELECT `p`.`title`, `p`.`content`, `f`.* FROM `mdk_posts` as `p`, `mdk_forum` as `f` WHERE `p`.`tid` = '{$tid}' AND `p`.`fid` = `f`.`fid` AND `p`.`child` = '0'" ) );

	//	[CH]	判断文章是否存在
	if( !$postsInfo )
	{
		$errMessage	=	'你所查看的文章不存在或已被删除';
		include	ME_SYSTEM . '/error.php';
	}

	/**
	 *	如果这里需要对权限进行设定
	 *	需要在这里进行操作
	 */

	include	ME_CORE . '/template.h.php';
	include	ME_CORE . '/ubb2html.lib.php';

	$ubb2html	=	&new ubb2html();
	$MDK['f']	= !isset( $MDK['f'] ) || empty( $MDK['f'] ) ? intval( $postsInfo['fid'] ) : $MDK['f'];

	$postsInfo['content']	=	MDKsubstr( strip_tags( htmlspecialchars_decode( $postsInfo['content'] ) ) );

	$forumName	=	getForumName( $postsInfo['fid'] );
	$currentForumUserInfo	=	getForumAdminInfo( $forumAdmin, $postsInfo['fid'] );

	//print_r( $postsInfo['firstParentId'] );

	$postsTotal		=	$db->assoc( $db->query( "SELECT COUNT( `p`.`id` ) as `total` FROM `mdk_posts` as `p`, `mdk_users` as `u`, `mdk_member` as `m` WHERE `p`.`tid` = '{$tid}' AND `p`.`uid` = `u`.`uid` AND `p`.`uid` = `m`.`uid`" ) );
	$dblimit		=	sqlLimit( ME_MAXPOSTSNUMBER );
	$page			=	parsePaging( $postsTotal['total'], $dblimit, ME_MAXPOSTSNUMBER );

	$postsResult	=	$db->query( "SELECT `p`.*, `u`.`username`, `m`.* FROM `mdk_posts` as `p`, `mdk_users` as `u`, `mdk_member` as `m` WHERE `p`.`tid` = '{$tid}' AND `p`.`uid` = `u`.`uid` AND `p`.`uid` = `m`.`uid` LIMIT {$dblimit[0]}, {$dblimit[1]}" );

	//	[CH]	计算当前楼层
	$i	=	( $MDK['p'] - 1 ) * ME_MAXPOSTSNUMBER;
	while( $row = $db->assoc( $postsResult ) )
	{
		$row['content']		=	$ubb2html->parse( /*preg_replace( "/([^|]\n\r|\n|\r|\t)+/s", '', */htmlspecialchars_decode( $row['content'], ENT_QUOTES ) ) /*)*/;
		$row['signature']	=	htmlspecialchars_decode( $row['signature'], ENT_QUOTES );
		$row['date']	=	date( "Y-m-d h:i:s [a]", $row['timestamp'] );
		$row['pid']		=	$i;
		$postsArray[]	=	$row;
		$i++;
	}

	$appRunTime	=	round( getCurrentTime() - $appStartTime, 4 );
	$viewLoaded	=	true;
?>